/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package domain.impl;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import domain.DomainPackage;
import domain.Entity;
import domain.Metric;
import domain.SystemHistory;
import domain.SystemVersion;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>System History</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link domain.impl.SystemHistoryImpl#getSystemVersion <em>System Version</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SystemHistoryImpl extends EObjectImpl implements SystemHistory {
	/**
	 * The cached value of the '{@link #getSystemVersion() <em>System Version</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSystemVersion()
	 * @generated
	 * @ordered
	 */
	protected EList<SystemVersion> systemVersion;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SystemHistoryImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DomainPackage.Literals.SYSTEM_HISTORY;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SystemVersion> getSystemVersion() {
		if (systemVersion == null) {
			systemVersion = new EObjectContainmentEList<SystemVersion>(SystemVersion.class, this, DomainPackage.SYSTEM_HISTORY__SYSTEM_VERSION);
		}
		return systemVersion;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DomainPackage.SYSTEM_HISTORY__SYSTEM_VERSION:
				return ((InternalEList<?>)getSystemVersion()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DomainPackage.SYSTEM_HISTORY__SYSTEM_VERSION:
				return getSystemVersion();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DomainPackage.SYSTEM_HISTORY__SYSTEM_VERSION:
				getSystemVersion().clear();
				getSystemVersion().addAll((Collection<? extends SystemVersion>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DomainPackage.SYSTEM_HISTORY__SYSTEM_VERSION:
				getSystemVersion().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DomainPackage.SYSTEM_HISTORY__SYSTEM_VERSION:
				return systemVersion != null && !systemVersion.isEmpty();
		}
		return super.eIsSet(featureID);
	}
	
	@Override
	public List<Metric> getMetricsOfTheFirstProject() {
		SystemVersion systemVersion = getSystemVersion().get(0);
		return systemVersion.getProjectEntity().getMetric();
	}

	@Override
	public List<Metric> getMetricsOfAllProjects() {
		List<Metric> metricsOfAllProjects = new LinkedList<Metric>();
		for (SystemVersion systemVersion : this.getSystemVersion()) {
			Entity entityFirstProject = systemVersion.getProjectEntity();
			for (Metric metric : entityFirstProject.getMetric()) {
				if(!metric.isContained(metricsOfAllProjects)){
					metricsOfAllProjects.add(metric);
				}
			}
		}
		
		return metricsOfAllProjects;
	}

} //SystemHistoryImpl
